function BuildingDrawn(type, day) {
    this.type = type;
    this.day = day;
    this.position = 0;
    this.ele = $('<div class="building"><img src="./img/bldg/' + type + '.png"/></div>');
    var dayTime = game.day + game.dayCounter/1000;
    this.position = (this.day - dayTime) * game.pxPerDay - 32;
    this.ele.css('left', this.position);
    $('#buildings').append(this.ele);
}

BuildingDrawn.prototype.update = function(ms) {
    var dayTime = game.day + game.dayCounter/1000;
    this.position = (this.day - dayTime) * game.pxPerDay - 32;
    this.ele.css('left', this.position);
    if (this.position < -128) {
        this.ele.remove();
        delete game.draw.buildings[this.day];
    }
}

function Draw() {
    this.buildings = {};
    
    /* dirty char props*/
    this.charImg = $('#char-sprite');
    this.curFrame = 0;
    this.frameWidth = 64;
    this.timer = 0;
    
    this.drawChar = function(ms) {
        this.timer = this.timer+ms;
        
        if (this.timer > 150) {
            this.curFrame++;
            
            if (this.curFrame >= 9) { this.curFrame = 0; }
            
            this.charImg.css('left', - 1* this.curFrame*this.frameWidth);
            this.timer = 0;
        }
    }
    
    this.city = $('#cityscape-img-1');
    this.citySpeed = 0.01;
    this.currentLeft = 0;
    
    this.cityWidth = 2560;
    this.gameWidth = 640;
    this.maxLeft = -1 * (this.cityWidth - this.gameWidth);
    this.baseLeft = -1 * (this.cityWidth/2 - this.gameWidth);
    
    this.drawCityscape = function(ms) {
        this.currentLeft -= ms * this.citySpeed;
        
        if (this.currentLeft < this.maxLeft) {
            this.currentLeft = this.baseLeft;
        }
        
        this.city.css('left', Math.round(this.currentLeft));
    }
    
    this.drawBuildings = function(ms) {
        for (var build in this.buildings) {
            if (build != null && build != undefined) {
                this.buildings[build].update(ms);
            }
        }
    }   
    
    this.building = function(type, day) {
        this.buildings[day] = new BuildingDrawn(type, day + 1);
        game.manager.lastBuildingDrawnDay=Math.max(game.lastBuildingDrawnDay,day); 
    }
    
    this.update = function(ms) {
        this.drawChar(ms);
        this.drawCityscape(ms);
        this.drawBuildings(ms);
    }
}